package com.champ.mc.thread.deadLockTest;

import com.champ.mc.thread.demo1.ThreadB;

public class DealThread implements Runnable{
    public String name;
    public Object lock1 = new Object();
    public Object lock2 = new Object();
    public void setFlag(String name) {
        this.name = name;
    }
    @Override
    public void run() {
        if (name.equals("a")) {
            synchronized (lock1) {
                try {
                    System.out.println("name==" + name);
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock2) {
                    System.out.println("lock1 -->  lock2");
                }
            }
        }
        if (name.equals("b")) {
            synchronized (lock2) {
                try {
                    System.out.println("name==" + name);
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock1) {
                    System.out.println("lock2 -->  lock1");
                }
            }
        }
    }
}
